#ifndef _MUMZIK_FUNC_H_
#define _MUMZIK_FUNC_H_

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "Mumzik.h"
#include "qsort.h"

using namespace std;

/* Reads data about mumziks from a file 
  Mumzik** mas_beg - pointer to pointer to the beginning of the array of mumziks
  Mumzik** mas_end - pointer to pointer to the element followin the last
  char* filename - data file name
*/
bool Read_Mumzik_from_file (Mumzik** mas_beg, Mumzik** mas_end, char* filename);

/* Writes data about mumziks from a file
  Mumzik** mas_beg - pointer to pointer to the beginning of the array of mumziks
  Mumzik** mas_end - pointer to pointer to the element following the last
  char* filename - date file name
*/
bool Write_Mumzik_to_file (Mumzik* mas_beg, Mumzik* mas_end, char* filename);

/* Exchange apples between two mumziks
  Mumzik* first - pointer to the first mumzik
  Mumzik* second - pointer to the second mumzik
 */
size_t Exchange_apples (Mumzik* first, Mumzik* second, size_t num_bask_exch);

/* Exchange apples between all mumziks
  Mumzik* left - pointer to the first element mumzik's array
  Mumzik* right - pointer to the element following the last mumzik's array
*/
size_t Global_exchange (Mumzik* left, Mumzik* right, size_t num_bask_exch);

/* Sort baskets of apples in ascending order of all mumziks 
  Mumzik* beg - pointer to the first element mumzik's array
  Mumzik* end - pointer to the element following the last mumzik's array
  Cmp cmp - comparator
*/
/* Sort baskets of apples in ascending order number of apples of all mumziks
  Mumzik* beg - pointer to the first element mumzik's array
  Mumzik* end - pointer to the element following the last mumzik's array
  Cmp cmp - comparator
*/
template <class Cmp>
void Sort_all_Mumzik (Mumzik* beg, Mumzik* end, Cmp cmp)
{
	for (Mumzik* i = beg; i != end; ++i)
		quicksort ( i->get_beg(), i->get_end(), cmp);
}

#endif